
//
//  PhotoCell.m
//  WXMovie
//
//  Created by HZApple on 16/4/6.
//  Copyright © 2016年 无限互联. All rights reserved.
//

#import "PhotoCell.h"

@implementation PhotoCell {
    UIImageView *imageView;
}


- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self _createImageView];
    }
    return self;
}

- (void)setImgUrlStr:(NSString *)imgUrlStr {
    _imgUrlStr = imgUrlStr;
    [imageView sd_setImageWithURL:[NSURL URLWithString:_imgUrlStr]];
}

- (void)_createImageView {
    imageView = [[UIImageView alloc] initWithFrame:self.bounds];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
   
    
    imageView.userInteractionEnabled = YES;
    
    [imageView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(savePicitureAction:)]];
    
    [self.contentView addSubview:imageView];
    
}

- (void)savePicitureAction:(UIGestureRecognizer *)longPress {
    
    if (longPress.state == UIGestureRecognizerStateBegan) {
        UIImage *img = imageView.image;
        if (img) {
            UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil) ;
        }
    }
   
    
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    NSLog(@"保存成功");
}

@end
